/**************************************************************
WinFilter version 0.8
http://www.winfilter.20m.com
akundert@hotmail.com

Filter type: Band Pass
Filter model: Chebyshev
Filter order: 6
Sampling Frequency: 48 KHz
Fc1 and Fc2 Frequencies: 10.000000 KHz and 14.000000 KHz
Pass band Ripple: 1.000000 dB
Coefficents Quantization: float

Z domain Zeros
z = -1.000000 + j 0.000000
z = -1.000000 + j 0.000000
z = -1.000000 + j 0.000000
z = -1.000000 + j 0.000000
z = -1.000000 + j 0.000000
z = -1.000000 + j 0.000000
z = 1.000000 + j 0.000000
z = 1.000000 + j 0.000000
z = 1.000000 + j 0.000000
z = 1.000000 + j 0.000000
z = 1.000000 + j 0.000000
z = 1.000000 + j 0.000000

Z domain Poles
z = -0.183404 + j -0.939332
z = -0.183404 + j 0.939332
z = -0.067127 + j -0.937535
z = -0.067127 + j 0.937535
z = -0.253317 + j -0.951415
z = -0.253317 + j 0.951415
z = 0.067127 + j -0.937535
z = 0.067127 + j 0.937535
z = 0.183404 + j -0.939332
z = 0.183404 + j 0.939332
z = 0.253317 + j -0.951415
z = 0.253317 + j 0.951415
***************************************************************/

#include "chebyshev_10KHz.h"

static float ACoef[NCoef+1] = {
    0.00149272725125322710,
    0.00000000000000000000,
    -0.00895636350751936180,
    0.00000000000000000000,
    0.02239090876879840400,
    0.00000000000000000000,
    -0.02985454502506454000,
    0.00000000000000000000,
    0.02239090876879840400,
    0.00000000000000000000,
    -0.00895636350751936180,
    0.00000000000000000000,
    0.00149272725125322710
};

static float BCoef[NCoef+1] = {
    1.00000000000000000000,
    0.00000000004877158481,
    5.12838889653415550000,
    0.00000000027219792236,
    11.32477765986082100000,
    0.00000000069332169482,
    13.74824826437459400000,
    0.00000000092427250797,
    9.66297990432003400000,
    0.00000000042135808649,
    3.72533592001323390000,
    0.00000000003217195002,
    0.61536834557211872000
};

float iir(float NewSample, IirData* data) {

    int n;

    //shift the old samples
    for(n=NCoef; n>0; n--) {
       data->x[n] = data->x[n-1];
       data->y[n] = data->y[n-1];
    }

    //Calculate the new output
    data->x[0] = NewSample;
    data->y[0] = ACoef[0] * data->x[0];
    for(n=1; n<=NCoef; n++)
        data->y[0] += ACoef[n] * data->x[n] - BCoef[n] * data->y[n];
    
    return data->y[0];
}

void iirInit(IirData* data)
{
    for(int n=0; n<=NCoef; n++)
    {
        data->x[n] = data->y[n] = 0;
    }
}
